package item16;

import java.util.Collection;
import java.util.HashSet;

public class InstrumentedHashSet01<E> extends HashSet<E> {

    // The number of attempted element insertions
    // 尝试插入元素的次数
    private int addCount = 0;

    public InstrumentedHashSet01() {
    }

    public InstrumentedHashSet01(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    @Override
    public boolean add(E e) {
        addCount++;
        return super.add(e);
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        addCount += c.size();
        return super.addAll(c);
    }

    public int getAddCount() {
        return addCount;
    }

}
